import { Controller, Post, Body, UseInterceptors, UploadedFile, Param } from "@nestjs/common";
import { FileInterceptor, FileFieldsInterceptor } from '@nestjs/platform-express'
import { Express } from "express";
import { FileService } from './file.service'
import { PagerDto } from "@dto/public.dto";
import { Permission } from "@decorators";

@Controller('file')
export class FileController {
	constructor(private readonly fileService: FileService) {}

    @Post()
    @Permission('file::list')
    getFileList(@Body() params: PagerDto) {
        return this.fileService.getFileList(params)
    }

    @Post('upload')
    @Permission('file::upload')
    @UseInterceptors(FileInterceptor('file'))
    updateFile(@UploadedFile() file: Express.Multer.File): any {
	    return this.fileService.updateFile(file)
    }

    @Post('download/:id')
    @Permission('file::download')
    download(@Param('id') fileId: string) {
	    return this.fileService.download(+fileId)
    }
}
